<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2022/10/3
  Time: 15:15
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<script src="js/jquery-1.8.3.js"></script>
<html>
<head>
    <title>添加个人简历信息</title>
</head>
<body>
<h1>添加个人简历信息</h1>
<form method="post" action="Add">
  <table border="1">
    <tr>
      <td>姓名</td>
      <td>
        <input type="text" name="userName" id="userName"><span></span>
      </td>
    </tr>
    <tr>
      <td>性别</td>
      <td>
        <input type="radio" name="sex" id="sexMale" value="男" checked> 男
        <input type="radio" name="sex" id="sexFemale" value="女"> 女
      </td>
    </tr>
    <tr>
      <td>籍贯地址</td>
      <td>
        <input type="text" name="address" id="address"><span></span>
      </td>
    </tr>
    <tr>
      <td>出生时间</td>
      <td>
        <input type="text" name="birth" id="birth"><span></span>
      </td>
    </tr>
    <tr>
      <td>联系方式</td>
      <td>
        <input type="text" name="telephone" id="telephone" onblur="checkPhone(this.value)"><span></span>
      </td>
    </tr>
    <tr>
      <td>毕业学校</td>
      <td>
        <input type="text" name="school" id="school"><span></span>
      </td>
    </tr>
    <tr>
      <td>简历状态</td>
      <td>
        <input type="radio" name="status" id="statusPublic" value="1" checked> 公开
        <input type="radio" name="status" id="statusPrivate" value="0"> 保密
      </td>
    </tr>
    <tr>
      <td>操作</td>
      <td>
        <input type="submit" value="新增">
        <input type="button" value="返回">
      </td>
    </tr>
  </table>
</form>
</body>
<script>
  $(function () {
    $('form').submit(function () {
      var userName = $('#userName').val();
      if(userName==''){
        $('#userName').next().html('姓名不能为空')
        return false;
      } else {
        $('#userName').next().html('')
      }

      var address = $('#address').val();
      if(address==''){
        $('#address').next().html('籍贯地址不能为空')
        return false;
      } else {
        $('#address').next().html('')
      }

      var birth = $('#birth').val();
      // 2022-11-11
      var reg = /^\d{4}-\d{2}-\d{2}$/
      if(!reg.test(birth)){
        $('#birth').next().html('格式不正确')
        return false;
      } else {
        $('#birth').next().html('')
      }

    });
  })

  function checkPhone(telephone) {
    $.getJSON("CountServlet","telephone="+telephone,function (data) {
      if (data.result>0){
        $('#telephone').next().html('手机号已存在')
      }else {
        $('#telephone').next().html('')
      }
    })
  }
</script>
</html>
